<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/cookie.js"></script>
</head>

<body>
    <button class="set">创建</button>
    <button class="get">获取</button>
    <button class="edit">修改</button>
    <button class="del">删除</button>
</body>
<script>

    // 如何删除cookie
    // 1. 把cookie的过期时间 设置为已经过去的时间
    // 2. 删除cookie时 简易先将cookie的值赋值为空,然后在刷新页面

    // 注意: 过期的cookie 虽然通过document.cookie无法获取,但是在网站信息中还会显示 一直等到关闭浏览器或刷新页面时 才会清除



    var set = document.getElementsByClassName("set")[0];
    var get = document.getElementsByClassName("get")[0];
    var edit = document.getElementsByClassName("edit")[0];
    var del = document.getElementsByClassName("del")[0];

    set.onclick = function () {
        setCookie("user", "a123123", 31 * 24 * 60 * 60);
        setCookie("pwd", "123123", 31 * 24 * 60 * 60);
        setCookie("phone", "17386141517");
        setCookie("email", "1272071495@qq.com");
    }


    get.onclick = function () {


        console.log(getCookie("user"));
        console.log(getCookie("pwd"));
        console.log(getCookie("phone"));
        console.log(getCookie("email"));
        console.log(getCookie("age"));
    }

    edit.onclick = function () {
        setCookie("user", "b123123", 31 * 24 * 60 * 60);
        setCookie("pwd", "321323", 31 * 24 * 60 * 60);
        setCookie("phone", "17386171514", 31 * 24 * 60 * 60);
        setCookie("email", "1272076666@qq.com", 31 * 24 * 60 * 60);
    }

    del.onclick = function () {
        // document.cookie = "";   //设置一条新的cookie (没有键值对 => 不生效)  

        // setCookie("user", "", -1);
        // setCookie("pwd", "", -1);
        // setCookie("phone", "", -1);
        // setCookie("email", "", -1);

        delCookie("user");
        delCookie("pwd");
        delCookie("phone");
        delCookie("email");

        location.reload();
    }


</script>

</html>